package com.ruoyi.health.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.health.domain.Resource;
import com.ruoyi.health.service.IResourceService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 养老资源Controller
 * 
 * @author dalian
 * @date 2023-08-06
 */
@RestController
@RequestMapping("/health/healthResource")
public class ResourceController extends BaseController
{
    @Autowired
    private IResourceService resourceService;

    /**
     * 查询养老资源列表
     */
    @PreAuthorize("@ss.hasPermi('health:healthResource:list')")
    @GetMapping("/list")
    public TableDataInfo list(Resource resource)
    {
        startPage();
        List<Resource> list = resourceService.selectResourceList(resource);
        return getDataTable(list);
    }

    /**
     * 导出养老资源列表
     */
    @PreAuthorize("@ss.hasPermi('health:healthResource:export')")
    @Log(title = "养老资源", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Resource resource)
    {
        List<Resource> list = resourceService.selectResourceList(resource);
        ExcelUtil<Resource> util = new ExcelUtil<Resource>(Resource.class);
        util.exportExcel(response, list, "养老资源数据");
    }

    /**
     * 获取养老资源详细信息
     */
    @PreAuthorize("@ss.hasPermi('health:healthResource:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(resourceService.selectResourceById(id));
    }

    /**
     * 新增养老资源
     */
    @PreAuthorize("@ss.hasPermi('health:healthResource:add')")
    @Log(title = "养老资源", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Resource resource)
    {
        resource.setCreateBy(getUsername());
        return toAjax(resourceService.insertResource(resource));
    }

    /**
     * 修改养老资源
     */
    @PreAuthorize("@ss.hasPermi('health:healthResource:edit')")
    @Log(title = "养老资源", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Resource resource)
    {
        return toAjax(resourceService.updateResource(resource));
    }

    /**
     * 删除养老资源
     */
    @PreAuthorize("@ss.hasPermi('health:healthResource:remove')")
    @Log(title = "养老资源", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(resourceService.deleteResourceByIds(ids));
    }
}
